module SinatraDemo
  module Models
    class Album < Sequel::Model
      many_to_one :artist
      def initialize
        super
      end
      def self.create(params)
        artwork = params[:artwork]
        artname = artwork[:filename]
        self.new do |a|
          a.title = params[:title]
          a.desc = params[:desc]
          a.artwork = Sequel.blob(artwork[:tempfile].read)
          a.artname = artname
          a.artist = Artist.find(:id=>params[:artist_id])
        end.save
      end
      def self.by_id(id)
        self[id]
      end
    end
  end
end